<?php

namespace Aanmelden\Controller;

class Index extends \Controller {
    
    public function index() {
        $this->_view = new \Aanmelden\Views\View();
        $this->_model = new \Aanmelden\Model\Index();
        if (filter_input(INPUT_POST,'knopaanmelden')) {
            $login = filter_input(INPUT_POST,'login',FILTER_SANITIZE_FULL_SPECIAL_CHARS);
            $this->_view->setData('login',$login);
            $wachtwoord = filter_input(INPUT_POST,'wachtwoord',FILTER_SANITIZE_FULL_SPECIAL_CHARS);
            if (empty($login) || empty($wachtwoord)) {
                $this->_view->setData('boodschap','beide velden vereist');
                $this->_view->genereer('Aanmelden','Index','index');            
            } elseif ($this->_model->valideerGebruiker($login,$wachtwoord)) {
                $this->_view->genereer('Aanmelden','Index','welkom');
            } else {
                $this->_view->setData('boodschap','Systeem kan je niet identificeren');
                $this->_view->genereer('Aanmelden','Index','index');  
            }
        } else {
            $this->_view->genereer('Aanmelden','Index','index');
        }
        \Weergave::GENEREER();
    }
    
    public function afmelden() {
        $this->_model = new \Aanmelden\Model\Index();
        $this->_model->afmelden();
        header('location:'.\instelling::GET('website.root'));
    }
}
